Page({
  data: {
    activeCategory: 'basic', // 当前选中分类
    categories: [
      { id: 'basic', name: '基础教育' },
      { id: 'vocational', name: '职业教育' },
      { id: 'higher', name: '高等教育' },
      { id: 'art', name: '艺术教育' }
    ],
    books: [
      {
        id: 1,
        title: '点亮特殊心灵：特殊教育的智慧与实践',
        author: '教育科学出版社',
        category: '基础教育',
        cover: '/images/book1.jpg',
        content: '本书详细介绍了特殊教育的理论与实践...',
        categoryId: 'basic'
      },
      {
        id: 2,
        title: '特殊教育：开启多元潜能之门',
        author: '人民教育出版社',
        category: '基础教育',
        cover: '/images/book2.jpg',
        content: '探讨如何通过特殊教育发掘学生潜能...',
        categoryId: 'basic'
      },
      {
        id: 3,
        title: '职业教育课程设计',
        author: '职教出版社',
        category: '职业教育',
        cover: '/images/book3.jpg',
        content: '职业教育课程开发与设计的专业指南...',
        categoryId: 'vocational'
      },
      // 更多书籍数据...
    ],
    filteredBooks: []
  },

  onLoad() {
    this.filterBooks();
  },

  // 切换分类
  switchCategory(e) {
    const categoryId = e.currentTarget.dataset.id;
    this.setData({
      activeCategory: categoryId
    }, () => {
      this.filterBooks();
    });
  },

  // 过滤书籍
  filterBooks() {
    const { activeCategory, books } = this.data;
    const filtered = activeCategory === 'all' 
      ? books 
      : books.filter(book => book.categoryId === activeCategory);
    
    this.setData({
      filteredBooks: filtered
    });
  },

  // 阅读书籍
  readBook(e) {
    const bookId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/books/reader?id=${bookId}`
    });
  }
});